//sum(1,2)(3)(4)(5,6,7)()返回28
function sum(...rest){
    let args = rest;//闭包
    if(rest.length==0) return 0
    return function fn(...rest){
        args = [...args,...rest]//继续拿到参数
        if(rest.length==0){//最后一个是()
            return args.reduce((pre,cur)=>pre+cur)
        }else{
            return fn//还没到最后
        }
    }
}
console.log(sum(1,2)(3)(4)(5,6,7)())
//柯里化呢

function add(a,b,c){
    return a+b+c
}
function curry(fn){
    let saveArgs = []
    return function next(...res){
        saveArgs = [...saveArgs,...res]
        if(saveArgs.length<fn.length){
            return next;
        }else{
            return fn.apply(null,saveArgs)
        }
    }
}

console.log(curry(add)(1)(2)(3))